﻿#region Copyright (c) 2000-2008 Developer Express Inc.
/*
{*******************************************************************}
{                                                                   }
{       Developer Express .NET Component Library                    }
{       AgDataGrid                                 }
{                                                                   }
{       Copyright (c) 2000-2008 Developer Express Inc.              }
{       ALL RIGHTS RESERVED                                         }
{                                                                   }
{   The entire contents of this file is protected by U.S. and       }
{   International Copyright Laws. Unauthorized reproduction,        }
{   reverse-engineering, and distribution of all or any portion of  }
{   the code contained in this file is strictly prohibited and may  }
{   result in severe civil and criminal penalties and will be       }
{   prosecuted to the maximum extent possible under the law.        }
{                                                                   }
{   RESTRICTIONS                                                    }
{                                                                   }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES           }
{   ARE CONFIDENTIAL AND PROPRIETARY TRADE                          }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS   }
{   LICENSED TO DISTRIBUTE THE PRODUCT AND ALL ACCOMPANYING .NET    }
{   CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY.                 }
{                                                                   }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                      }
{                                                                   }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON       }
{   ADDITIONAL RESTRICTIONS.                                        }
{                                                                   }
{*******************************************************************}
*/
#endregion Copyright (c) 2000-2008 Developer Express Inc.

using System;
using System.Collections.Generic;
using System.Windows;
using Microsoft.Silverlight.Testing;
using Microsoft.Silverlight.Testing.Harness;
using Microsoft.Silverlight.Testing.UnitTesting.Harness;
using Microsoft.Silverlight.Testing.UnitTesting.Metadata;
namespace DevExpress.AgDataGrid.Tests {
	public partial class App : Application {
		public App() {
			this.Startup += this.Application_Startup;
			this.Exit += this.Application_Exit;
			this.UnhandledException += this.Application_UnhandledException;
			InitializeComponent();
		}
		void Application_Exit(object sender, EventArgs e) { }
		void Application_Startup(object sender, StartupEventArgs e) {
			UnitTestSettings settings = UnitTestSystem.CreateDefaultSettings();
			settings.LogProviders.Add(new ConsoleLogProvider());
			settings.TestHarness = new CustomUnitTestHarness();
			this.RootVisual = UnitTestSystem.CreateTestPage(settings);
		}
		void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) { }
	}
	class ConsoleLogProvider : LogProvider {
		public override void Process(LogMessage logMessage) {
			Console.WriteLine(DateTime.Now.ToLongTimeString() + ": " + logMessage.ToString());
		}
	}
	class CustomUnitTestHarness : UnitTestHarness {
		protected override TestRunFilter CreateTestRunFilter(UnitTestSettings settings) {
			return new CustomTestRunFilter(settings, this);
		}
	}
	class CustomTestRunFilter : TestRunFilter {
		public CustomTestRunFilter(UnitTestSettings settings, UnitTestHarness harness) : base(settings, harness) { }
		protected override void FilterCustomTestClasses(IList<ITestClass> classes, TestClassInstanceDictionary instances) {
			if (!HasClassNameWithFirstUnderscore(classes)) return;
			for (int i = classes.Count - 1; i >= 0; i--)
				if (classes[i].Name[0] != '_')
					classes.RemoveAt(i);
		}
		protected virtual bool HasClassNameWithFirstUnderscore(IList<ITestClass> classes) {
			foreach (ITestClass testClass in classes)
				if (testClass.Name[0] == '_')
					return true;
			return false;
		}
	}
}
